package com.ycdx.zwzc.action;

import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.Preparable;
import com.ycdx.zwzc.impl.ServiceTypeImpl;
import com.ycdx.zwzc.impl.SymptomImpl;
import com.ycdx.zwzc.pojo.ServiceType;
import com.ycdx.zwzc.pojo.Symptom;

public class SymptomAction extends ActionSupport implements Preparable{
	
	private List<Symptom> allSymptoms;
	private List<ServiceType> allServiceType;
	private Symptom symptom;
	private String id;
	
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public Symptom getSymptom() {
		return symptom;
	}
	public void setSymptom(Symptom symptom) {
		this.symptom = symptom;
	}
	public List<ServiceType> getAllServiceType() {
		return allServiceType;
	}
	public void setAllServiceType(List<ServiceType> allServiceType) {
		this.allServiceType = allServiceType;
	}
	private static final long serialVersionUID = -512728776868877795L;
	
	
	
	public List<Symptom> getAllSymptoms() {
		return allSymptoms;
	}
	public void setAllSymptoms(List<Symptom> allSymptoms) {
		this.allSymptoms = allSymptoms;
	}
	public String show(){
		return "success";
	}
	public String add(){
		return "success";
	}
	/**
	 * 添加障碍现象
	 * @return
	 */
	public String addNew(){
		int flag = SymptomImpl.addSymptom(symptom);
		//System.out.println(request.getEditor());
		if(flag==1){
			//添加成功
			addActionMessage("障碍现象添加成功！");
			
		}else{
			//添加不成功
			addActionMessage("障碍现象添加不成功，请重试！");
			
		}
		return "list";
	}
	
	public String edit(){
		//System.out.println(id);
		symptom = SymptomImpl.getSymptomById(id);
		return "success";
	}
	
	/**
	 * 障碍现象修改
	 * @return
	 */
	public String update(){
		int flag = SymptomImpl.update(symptom);
		//System.out.println(request.getEditor());
		if(flag==1){
			//添加成功
			addActionMessage("障碍现象修改成功！");
			
		}else{
			//添加不成功
			addActionMessage("障碍现象修改不成功，请重试！");
			
		}
		return "list";
	}
	
	public String delete(){
		//System.out.println(id);
		int flag = SymptomImpl.deleteSymptom(id);
		//System.out.println(flag);
		if(flag==1){
			//删除成功
			addActionMessage("障碍现象删除成功！");
			
		}else{
			//添加不成功
			addActionMessage("障碍现象删除不成功，请重试！");
			
		}
		return "list";
	}
	/**
	 * 初始化产品类型
	 */
	public void prepare() throws Exception {
		// TODO Auto-generated method stub
		allSymptoms = SymptomImpl.queryAllSymptom();
		allServiceType = ServiceTypeImpl.queryAllServiceType();
	}
}
